package sqlite3

import (
	"github.com/jinzhu/gorm"
	_ "github.com/jinzhu/gorm/dialects/sqlite"
	"log"
)

//OpenMysql connect to Mysql database or exit
func OpenSqlite3() *gorm.DB {
	db, err := gorm.Open("sqlite3", "./gorm.db")
	if err != nil {
		log.Fatalf("OpenSqlite3 gorm.Open err: %s!\n", err.Error())
	}

	// set table defaultName
	gorm.DefaultTableNameHandler = func(db *gorm.DB, defaultTableName string) string {
		return "tb_" + defaultTableName
	}

	// close
	db.SingularTable(true)

	return db
}
